package com.ruoyi.web.controller.mall.goodsTypeSpec.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.goodsTypeSpec.domain.GoodsTypeSpec;
import com.ruoyi.web.controller.mall.goodsTypeSpec.service.IGoodsTypeSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类型规格关联Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/goodsTypeSpec")
public class GoodsTypeSpecController extends BaseController
{
    private String prefix = "mall/goodsTypeSpec";

    @Autowired
    private IGoodsTypeSpecService goodsTypeSpecService;

//    @RequiresPermissions("mall:goodsTypeSpec:view")
    @GetMapping()
    public String goodsTypeSpec()
    {
        return prefix + "/goodsTypeSpec";
    }

    /**
     * 查询类型规格关联列表
     */
//    @RequiresPermissions("mall:goodsTypeSpec:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsTypeSpec goodsTypeSpec)
    {
        startPage();
        List<GoodsTypeSpec> list = goodsTypeSpecService.selectGoodsTypeSpecList(goodsTypeSpec);
        return getDataTable(list);
    }

    /**
     * 导出类型规格关联列表
     */
//    @RequiresPermissions("mall:goodsTypeSpec:export")
    @Log(title = "类型规格关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsTypeSpec goodsTypeSpec)
    {
        List<GoodsTypeSpec> list = goodsTypeSpecService.selectGoodsTypeSpecList(goodsTypeSpec);
        ExcelUtil<GoodsTypeSpec> util = new ExcelUtil<GoodsTypeSpec>(GoodsTypeSpec.class);
        return util.exportExcel(list, "goodsTypeSpec");
    }

    /**
     * 新增类型规格关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存类型规格关联
     */
//    @RequiresPermissions("mall:goodsTypeSpec:add")
    @Log(title = "类型规格关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsTypeSpec goodsTypeSpec)
    {
        return toAjax(goodsTypeSpecService.insertGoodsTypeSpec(goodsTypeSpec));
    }

    /**
     * 修改类型规格关联
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GoodsTypeSpec goodsTypeSpec = goodsTypeSpecService.selectGoodsTypeSpecById(id);
        mmap.put("goodsTypeSpec", goodsTypeSpec);
        return prefix + "/edit";
    }

    /**
     * 修改保存类型规格关联
     */
//    @RequiresPermissions("mall:goodsTypeSpec:edit")
    @Log(title = "类型规格关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsTypeSpec goodsTypeSpec)
    {
        return toAjax(goodsTypeSpecService.updateGoodsTypeSpec(goodsTypeSpec));
    }

    /**
     * 删除类型规格关联
     */
//    @RequiresPermissions("mall:goodsTypeSpec:remove")
    @Log(title = "类型规格关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(goodsTypeSpecService.deleteGoodsTypeSpecByIds(ids));
    }
}
